<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page import="javax.jdo.PersistenceManager"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="com.joe.rememberanything.model.Item"%>
<%@ page import="com.joe.rememberanything.dao.PMF"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
		<style type="text/css">
		</style>
		<script src="/javascript/jquery/jquery.js"></script>
		<script src="/javascript/jquery/plugins/eyecon/interface.js"></script>
		<script type="text/javascript">
			$(function(){
				$('ul').Sortable(
					{
						accept : 		'sortableitem',
						helperclass : 	'sorthelper',
						activeclass : 	'sortableactive',
						hoverclass : 	'sortablehover',
						opacity: 		0.8,
						fx:				200,
						axis:			'vertically',
						opacity:		0.4,
						revert:			true
					}
				)
			});
		</script>
	</head>
	<body>
<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
	<p>Hello, <%= user.getNickname() %>! (You can <a
	href="<%= userService.createLogoutURL("../item") %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello! <a href="<%= userService.createLoginURL("../item") %>">Sign in</a> 
to include your name with greetings you post.</p>
<%
    }
%>
<div style="float:left;width:50%">
<%
    List<Item> items = (List<Item>) request.getAttribute("items");
    if (items.isEmpty()) {
%>
The guestbook has no messages.
<%
    } else {
%>
<ul class="sortul">
<%
		for (Item item : items) {
%>
	 
	<!--hr size="1" noshade="noshade" style="border: 1px #cccccc dashed;" /-->
	<li class="sortableitem">
	<table class="infobox" width="100%">
		<tbody>
			<tr>
				<td class="item">
					<%=item.getTitle() %> -> 
					<span class="content">
						<%=StringUtils.trimToEmpty(item.getContent()) %> 
					</span>
					at 
					<%=item.getCreateTime().toLocaleString() %>
					<span float="right">
						<a href="/item?cmd=delete&id=<%=item.getId() %>">delete</a>
					</span>
				</td>
			</tr>
		</tbody>
	</table>
	</li>
<%
		}
%>
	</ul>
<%
    }
%>
</div>
<div style="float:right;width:30%;">
<form action="/item" method="post">
<input type="hidden" name="cmd" value="newItem"/>
<table class="grayTable">
<tr>
	<th>title:</th>
	<td><input type="text" name="title"/></td>
</tr>
<tr>
	<th>content:</th>
	<td><input type="text" name="content"/></td>
</tr>
<tr>
	<th>label</th>
	<td><input type="text" name="labelID"/></td>
</tr>
<tr>
	<th>state</th>
	<td><input type="text" name="state" value="0"/></td>
</tr>
<tr>
	<th>position</th>
	<td><input type="text" name="position"/></td>
</tr>
<tr>
	<th>status</th>
	<td><input type="text" name="status" value="1"/></td>
</tr>
<tr>
	<th>level</th>
	<td><input type="text" name="level" value="3"/></td>
</tr>
<tr>
	<td colspan="2">
		<input type="submit" value="submit"/>
		<input type="reset" value="reset"/>
	</td>
</tr>
</table>
</form>
</div>
</body>
</html>